package admin_login_handler

import (
	admin_login_service "oc_saas/internal/app/api/admin/login/service"
	admin_login_types "oc_saas/internal/app/api/admin/login/types"
	"oc_saas/internal/types/api"

	"github.com/gin-gonic/gin"
)

type Login struct {
	api.Api
}

// 后台登录api
//
//	@Tags		后台登录
//	@Summary	后台登录api
//	@accept		application/json
//	@Produce	application/json
//	@Param		data	body		admin_login_types.LoginBody	true	"账号，密码"
//	@Success	200		{object}	string						"后台登陆api"
//	@Router		/admin/login [post]
func (e Login) Login(c *gin.Context) {
	req := admin_login_types.LoginBody{}
	s := &admin_login_service.Login{}
	res := admin_login_types.LoginRes{}
	err := e.MakeContext(c).Bind(&req, api.JSON).Valid(&req).MakeOrm().MakeService(&s.Service).Errors
	if err != nil {
		panic(err)
	}
	s.Login(&req, &res)
	e.OkWithData(gin.H{"access_token": res.Token}, c)
}

// @Tags		后台退出登录
// @Summary	后台退出登录api
// @accept		application/json
// @Produce	application/json
// @Success	200	{object}	string	"后台退出陆api"
// @Router		/admin/logout [post]
func (e Login) LogOut(c *gin.Context) {
	e.Ok(c)
}

var LoginApi = new(Login)
